package cn.bopomo.dealer.base.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.bopomo.dealer.base.common.ServiceConfig;
import cn.bopomo.dealer.base.service.IOperatorService;
import cn.bopomo.dealer.base.util.ResultCode;
import cn.bopomo.dealer.base.vo.ModuleList;

public class ModuleModifyAction extends BaseAction {

	private String codeDescXMLPath = "/WEB-INF/code_description.xml";
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		response.setContentType("text/html;charset=UTF-8");
		response.setHeader("Cache-control","no-cache");
	
		StringBuffer result = new StringBuffer();
		
		if (!this.hasPermission(request)){
			result.append(ResultCode.OP_NO_PRIMITION).append("||").append("你没有该操作权限，请与管理员联系");
			response.getWriter().write(result.toString());
			return null;
		}
		
		String module_id = request.getParameter("mid");
		IOperatorService os = (IOperatorService)this.findService(ServiceConfig.OPERATOR_SERVICE);
		ModuleList module = os.getModule(new Integer(module_id));
		if (module == null){
			result.append(ResultCode.OP_FAILED).append("||").append("没有该功能模块的信息");
		}
		
		String module_name = request.getParameter("module_name");
		String module_tag = request.getParameter("module_tag");
		module.setModifyDate(new Date());
		module.setModuleName(module_name == null ? "" : module_name);
		module.setModuleTag(module_tag == null ? "" : module_tag);
		String check_result = ResultCode.OP_FAILED;
		
		check_result = os.modifyModule(module);
		result.append(check_result).append("||").append(this.getCodeDescription(check_result,request.getSession().getServletContext().getResource(this.codeDescXMLPath).getPath()));
		response.getWriter().write(result.toString());
		return null;
	}
	
}
